
/*
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */


%{

#include "config.h"

#include <stdio.h>
#include <string.h>

#include "main.h"

#include "parse.h"
#include "uniqstring.h"

char *laststring;
char *lastid;
char *lastnum;

#define MAXSTRING 22*1024


%}

	/* for lint purists according to flex manual */
%option nounput

	/* suppress gcc warning input() defined but not used */
%option noinput

	/* input does not come from a tty. */
%option never-interactive

	/* no yywrap() at end of file */
%option noyywrap

	/* 8-bits scanner */
%option 8bit

	/* generate line number */
%option yylineno


ISTR	[^\\\"]|\\.|\\\n
STR	\"({ISTR}*)\"
CCS	\/\*[^\*]*\*+([^\*\/][^\*]*\*+)*\/
CCE	\/\/[^\n]*

%%

"color" { return (TYS_COLOR); }
"digraph" { return (TYS_DIGRAPH); }
"edge" { return (TYS_EDGE); }
"folded" { return (TYS_FOLDED); }
"fontname" { return (TYS_FONTNAME); }
"fontsize" { return (TYS_FONTSIZE); }
"graph" { return (TYS_GRAPH); }
"label" { return (TYS_LABEL); }
"node" { return (TYS_NODE); }
"settings" { return (TYS_SETTINGS); }
"shape" { return (TYS_SHAPE); }
"strict" { return (TYS_STRICT); }
"style" { return (TYS_STYLE); }
"subgraph" { return (TYS_SUBGRAPH); }
"textcolor" { return (TYS_TEXTCOLOR); }
"textslant" { return (TYS_TEXTSLANT); }
"textweight" { return (TYS_TEXTWEIGHT); }
"void" { return (TYS_VOID); }
"xml" { return (TYS_XML); }

[\f ]+ { }
[\t] { }
[\n] { }

{STR} {
	char *p;
	char c;
	int i;
	char buf[MAXSTRING];
	yytext[strlen(yytext)-1] = '\0'; 
	p = yytext;
	i = 0;
	memset (buf,0,MAXSTRING);
	while (*p++)
	{
	 if (*p == '\\') {
	  p++;
	  if (*p == 'n') {
	   c = '\n';
	  } else if (*p == 'l') {
	   c = ' ';
	  } else if (*p == '"') {
	   c = '"';
	  } else {
	   buf[i] = '\\';
	   i = i + 1;
	   if (i == MAXSTRING -1) {
	    break;
	   }
	   c = *p;
	  }
	 } else {
	  c = *p;
	 }
	 buf[i] = c;
	 if (i == MAXSTRING -1) {
	  break;
	 }
	 i++;
	}
	laststring = uniqstring(buf); 
	return (TYS_STRING); 
      }

{CCS} { }
{CCE} { }

"{" { return ('{'); }
"}" { return ('}'); }
"(" { return ('('); }
")" { return (')'); }
"=" { return ('='); }
"," { return (','); }
";" { return (';'); }
"<" { return ('<'); }
"?" { return ('?'); }


. { return (yytext[0]); }

%%

void tyslexinit (FILE *f)
{
 if (f) {}
 return;
}

void tyslexreset (void)
{
 yylex_destroy ();
 return;
}

int tyslex_lineno (void)
{
 return (yylineno);
}

/* End */
